package com.os.meituan.service.sec;

import com.os.meituan.model.pomodel.sec.SEC_User;
import com.os.meituan.repository.User.EPLC_SEC_UserResponsitory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.Base64;

@Service
public class EPLC_SEC_UserService {
@Resource
private EPLC_SEC_UserResponsitory eplc_sec_userResponsitory;
    // 用eplc一样的加密方式加密密码
    public String encryptLikeEplc(String text) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] byte_temp = text.getBytes(StandardCharsets.UTF_8);
            md.update(byte_temp);
            byte[] b = md.digest();
            return Base64.getEncoder().encodeToString(b);
        } catch (Exception e) {
            return "";
        }
    }

    public SEC_User getModelExByLoginId(String loginId) {
        var info = eplc_sec_userResponsitory.findByLoginIdAndIsDelete(loginId, 0);
        if (info == null) {
            return null;
        }
        exFullModel(info);
        return info;
    }

    public void exFullModel(SEC_User info) {
        exBaseModel(info);

    }

    public void exBaseModel(SEC_User info) {
        info.setId(info.getId().toUpperCase());

    }
}
